package com.myCommon.security.controller;

import com.myCommon.security.entity.User;
import com.myCommon.security.service.UserService;
import com.myCommon.util.resultUtil.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
      
      @Autowired
      private UserService userService;
      
      @PostMapping("/login")
      public R login(@RequestBody User user){
            String token = userService.login(user);
            return R.ok().data("token",token);
      }
      
      @PostMapping("/logout")
      public R logout(){
            userService.logout();
            return R.ok(200, "退出成功");
      }
      
      @GetMapping("/getUserAll")
      @PreAuthorize("@hasAuthority('dev:pull')")
      public R getUserAll() {
            User user = userService.getById(1);
            return R.ok().data("user",user);
      }
}
